﻿using System;
using UnityEngine;
using Framework.Manager;

namespace Framework.UI
{
    public class UIToggle : UIBase
    {

        private ExToggle mExToggle = null;

        [SerializeField]
        private string mSoundName = "Sound_ToggleChange";

        public bool IsOn
        {
            get { return mExToggle.isOn; }
            set { mExToggle.isOn = value; }
        }

        public string SoundName
        {
            get { return mSoundName; }
            set { mSoundName = value; }
        }


        public Action<bool> OnValueChange { get; set; }

        protected override void OnAwake()
        {
            mExToggle = GetComponent<ExToggle>("ExToggle");
            mExToggle.onValueChanged.AddListener(OnValueChanged);
        }

        private void OnValueChanged(bool pIsOn)
        {
            if (Application.isPlaying)
            {
                ManagerCollection.AudioManager.PlaySound(mSoundName);
                OnValueChange?.Invoke(pIsOn);
            }
        }

        #region 编辑器相关
        protected override void OnValidate()
        {
            this.Awake();
        }
        #endregion
    }
}